package com.e3.basdoc.warehouse.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.warehouse.model.WarehouseModel;
import com.e3.basdoc.warehouse.model.WarehouseQC;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.web.core.client.GXTHelper;
import com.e3.web.core.client.GwtAsyncCallback;
import com.e3.web.core.model.SuperQC;
import com.e3.web.widget.client.MyField;
import com.extjs.gxt.ui.client.widget.form.Field;

public class WarehouseQueryDialog extends TGFQueryDialog<WarehouseModel> {
	private WarehouseRPCServiceAsync service = WarehouseRPCService.Util.getInstance();

	@Override
	protected List<Field<?>> getFormFields() {
		String[] fNames = {
				WarehouseModel.CODE
				,WarehouseModel.NAME
				,WarehouseModel.TYPE
				,WarehouseModel.STATUS
				};
		
		List<Field<?>> fields = new ArrayList<Field<?>>(fNames.length);
		for (String name : fNames) {
			fields.add(WarehouseHelper.INSTANCE.createFormField(name));
		}
		return fields;
	}

	@Override
	protected SuperQC getQueryCondition() {
		MyField field = getMyFormField(WarehouseModel.CODE);
		String code = (String)field.getFieldValue();
		field = getMyFormField(WarehouseModel.NAME);
		String name = (String)field.getFieldValue();
		field = getMyFormField(WarehouseModel.STATUS);
		String status = (String)field.getFieldValue();
		field = getMyFormField(WarehouseModel.TYPE);
		String type = (String)field.getFieldValue();
		
		final WarehouseQC qc = new WarehouseQC();
		qc.setCode(code);
		qc.setName(name);
		qc.setStatus(status);
		qc.setType(type);
		return qc;
	}

	@Override
	protected void executeQueryService(SuperQC qc,GwtAsyncCallback<List<WarehouseModel>> callback) {
		service.getWarehouseByCondition((WarehouseQC)qc, getQueryAsyncCallBack(qc));
	}
}
